package yunhe.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import yunhe.biz.IProcureBiz;
import yunhe.biz.impl.ProcureBizImpl;
import yunhe.entity.Product;
import yunhe.entity.Purchase;
import yunhe.entity.PurchaseAppend;
import yunhe.entity.Storage;
@WebServlet(name="InsertPurchaseAppendServlet",urlPatterns="/InsertPurchaseAppendServlet")
public class InsertPurchaseAppendServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		IProcureBiz ipb=new ProcureBizImpl();
		PurchaseAppend purchaseAppend=new PurchaseAppend();
		String pursId=request.getParameter("pursId");
		Purchase purchase=new Purchase();
		purchase.setPursId(pursId);
		purchaseAppend.setPurchase(purchase);
		String proBarCode=request.getParameter("proBarCode");
		Product product=new Product();
		product.setProBarCode(proBarCode);
		purchaseAppend.setProduct(product);
		String	purQuan=request.getParameter("purQuantity");
		int purQuantity=Integer.parseInt(purQuan);
		purchaseAppend.setPurQuantity(purQuantity);
		String purPri=request.getParameter("purPrice");
		double purPrice=Double.parseDouble(purPri);
		purchaseAppend.setPurPrice(purPrice);
		String purDis=request.getParameter("purDiscount");
		double purDiscount=Double.parseDouble(purDis);
		purchaseAppend.setPurDiscount(purDiscount);
		String purTot=request.getParameter("purTotal");
		double purTotal=Double.parseDouble(purTot);
		purchaseAppend.setPurTotal(purTotal);
		String purStorage=request.getParameter("purStorage");
		Storage storage=new Storage();
		storage.setStoName(purStorage);
		storage=ipb.selectStorageByStorageName(storage);
		purchaseAppend.setStorage(storage);
		boolean flag=ipb.insertPurchaseAppend(purchaseAppend);
		PrintWriter out=response.getWriter();
		if(flag){
			out.print("<script>alert('添加采购单成功');location.href='/purchase/purchaseCreate.jsp'</script>");
		}else{
			out.print("<script>alert('添加采购单失败');location.href='/purchase/purchaseAppend.jsp'</script>");
		}
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
